#!/bin/bash -e

# Date 		: 2020.12.20
# Author	: majin
# Mail 		: xx
# Function	: esay to push
# Version 	: 1.0
# Update 	: 2021.04.18

RES="\033[0m" ;BLUE="\033[36m";PURPLE="\033[35m"
info_msg(){ echo -e "${BLUE}info_msg: $1 ${RES}";}
warn_msg(){ echo -e "${PURPLE}warn_msg: $1 ${RES}";}

# record now time
now_time=`date -d today +"%Y-%m-%d-%H-%M"` 
commit_msg=$1
if [ ! ${commit_msg} ];then
 warn_msg "USAGE: \"commit_msg\""
 exit
fi
info_msg "commit_msg is: \"${commit_msg}\""

push_array=(
    "src/"
    "tools/"
    "test/sort_test.c"
    "CMakeLists.txt"  
    "README.md"  
    "mypush.sh"
)
push_len=${#push_array[@]}

info_msg "git add list:"
for ((i=0;i<${push_len};i+=1))
do
    info_msg "${push_array[i]}"
    git add ${push_array[i]}
done
# save msg
git config --local credential.helper store

# update git
git commit -m "${commit_msg}"
git pull
git push 